//package com.utils.spring.shirospringboot;
//
//import java.util.List;
//
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.shiro.authc.AuthenticationException;
//import org.apache.shiro.authc.AuthenticationInfo;
//import org.apache.shiro.authc.AuthenticationToken;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.kyhd.dshp.manage.model.Menu;
//import com.kyhd.dshp.manage.model.Role;
//import com.kyhd.dshp.manage.model.User;
//import com.kyhd.dshp.manage.service.MenuService;
//import com.kyhd.dshp.manage.service.RoleService;
//
//
///**
// * 统一角色授权控制策略
// */
//public class AuthorizationRealm extends AuthorizingRealm {
//
//	@Autowired
//	private RoleService roleService;
//	@Autowired
//	private MenuService menuService;
//
//	/**
//	 * 授权
//	 */
//	@Override
//	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//		System.out.println("---------------- 执行 Shiro 权限获取 ---------------------");
//		Object principal = principals.getPrimaryPrincipal();
//		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//		if (principal instanceof User) {
//			User userLogin = (User) principal;
//			if (userLogin != null) {
//				List<Role> roleList = roleService.findByUserid(userLogin.getId());
//				if (CollectionUtils.isNotEmpty(roleList)) {
//					for (Role role : roleList) {
//						info.addRole(role.getEnname());
//
//						List<Menu> menuList = menuService.getAllMenuByRoleId(role.getId());
//						if (CollectionUtils.isNotEmpty(menuList)) {
//							for (Menu menu : menuList) {
//								if (StringUtils.isNoneBlank(menu.getPermission())) {
//									info.addStringPermission(menu.getPermission());
//								}
//							}
//						}
//					}
//				}
//			}
//		}
//		System.out.println("---------------- 获取到以下权限 ----------------");
//		System.out.println(info.getStringPermissions().toString());
//		System.out.println("---------------- Shiro 权限获取成功 ----------------------");
//		return info;
//	}
//
//	/**
//	 * 认证信息.(身份验证) : Authentication 是用来验证用户身份
//	 *
//	 */
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
//			throws AuthenticationException {
//		return null;
//	}
//}
